﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum SoldierTrasition
{
    NullTranstion=0,
    CanSeeEnemey,
    InAttackDistance,
    LostEnemy
}
public enum SoldierStateID
{
    NullSoldierState=0,
    Idle,
    Attack,
    Chase
}
/// <summary>
/// 参考wiki.unity3d.com中对有限状态机的介绍做出对人物AI的状态基类
/// </summary>
public abstract class ISoldierState  {
    //字典存储转换状态
    protected Dictionary<SoldierTrasition, SoldierStateID> map = new Dictionary<SoldierTrasition, SoldierStateID>();
    //当前状态以及获得状态的方法
    protected SoldierStateID m_stateID;
    //当前角色
    protected Character m_character;
    //当前的AI处理系统
    protected SoldierFSMSystem m_FSM;



    public SoldierStateID GetStateID
    {
        get { return m_stateID; }
    }
    
    public ISoldierState(SoldierFSMSystem fsm ,Character character)
    {
        m_FSM = fsm;
        m_character = character;
    }


    //加入到字典的方法
    public void AddTransition(SoldierTrasition transiton,SoldierStateID stateID)
    {
        //安全校验
        if (transiton == SoldierTrasition.NullTranstion) Debug.LogError("NullTransiton");
        if (stateID == SoldierStateID.NullSoldierState) Debug.LogError("NullStateID");
        if (map.ContainsKey(transiton)) Debug.LogError("Contains " + transiton.ToString());
        //实现
        map.Add(transiton, stateID);
    }
    //从字典中删除
    public void DeleteTransition(SoldierTrasition transiton)
    {
        //安全校验
        if (transiton == SoldierTrasition.NullTranstion) Debug.LogError("NullTranstion");
        if (!map.ContainsKey(transiton)) Debug.LogError("dosen't exit " + transiton.ToString());
        //实现
        map.Remove(transiton);
    }

    /// <summary>
    /// 在转换状态中获得下一个状态
    /// </summary>
    /// <param name="transition"></param>
    /// <returns></returns>
    public SoldierStateID GetStateIDFromTransition(SoldierTrasition transition)
    {
        return SoldierStateID.NullSoldierState;
    }

    /// <summary>
    /// 进入该状态的时候的动作
    /// </summary>
    public virtual void  DoBeforeEntering() { }
    /// <summary>
    /// 离开该状态时候的动作
    /// </summary>
    public virtual void DoBeforeLeaving() { }
    /// <summary>
    /// 该状态需要做的 每帧调用
    /// </summary>
    public abstract void Act(List<Character> targets);
    /// <summary>
    /// 该状态切换到另一个状态的条件判断
    /// </summary>
    public abstract void Reason(List<Character> targets);
}

